//
//  ParseUint.swift
//  DriverSchoolAPP
//
//  Created by Logel on 2017/4/20.
//  Copyright © 2017年 Logel. All rights reserved.
//

import Foundation

func parseUser(x:JSON)-> User{
    var u = User()
    u.accountId = x["info"]["accountId"].stringValue
    u.teacherId = x["info"]["detail"]["teacherId"].stringValue
    u.placeId = x["info"]["detail"]["placeId"].stringValue
    u.userName = x["info"]["detail"]["userName"].stringValue
    u.token = x["token"].stringValue
    u.refreshToken = x["refreshToken"].stringValue
    u.driverSchoolId = x["info"]["detail"]["driverSchoolId"].stringValue
    u.placeName = x["info"]["detail"]["placeName"].stringValue
    u.schoolName = x["info"]["detail"]["schoolName"].stringValue
    u.name = x["info"]["detail"]["name"].stringValue
    u.address = x["info"]["detail"]["address"].stringValue
    u.signUpTime = x["info"]["detail"]["signUpTime"].stringValue
    u.placePhone = x["info"]["detail"]["placePhone"].stringValue
    return u
}

func parseUserList(all:[JSON])->[User]{
    var uList = [User]()
    for x in all{
        let u = parseUser(x: x)
        uList += [u]
    }
    return uList
}


func parseMobileHead(x:JSON)->MobileHead{
    var m = MobileHead()
    m.code = x["Code"].stringValue
    m.message = x["Message"].stringValue
    return m
}

func parseFirsePage(x:JSON)->FirsePage{
    var f = FirsePage()
    f.id = x["id"].stringValue
    f.link = x["link"].stringValue
    f.order1 = x["order1"].stringValue
    f.picture = x["picture"].stringValue
    f.status = x["status"].stringValue
    f.title = x["title"].stringValue
    return f
}

func parseFirstPageList(all:[JSON])->[FirsePage]{
    var fList = [FirsePage]()
    for x in all{
        let f = parseFirsePage(x: x)
        fList += [f]
    }
   
    return fList
}

func parseNearBy(x:JSON)->NearBy{
    var m = NearBy()
    m.id = x["id"].stringValue
    m.sId = x["sId"].stringValue
    m.name = x["name"].stringValue
    m.address = x["address"].stringValue
    m.picture = x["picture"].stringValue
    return m
}

func parseNearByList(all:[JSON])->[NearBy]{
    var nList = [NearBy]()
    for x in all {
        let f = parseNearBy(x: x)
        nList += [f]
    }
    return nList
}

func parseMyCourse(x:JSON)->MyCourse{
    var m = MyCourse()
    m.id = x["id"].stringValue
    m.status = x["status"].stringValue
    m.courseName = x["courseName"].stringValue
    m.classTime = x["classTime"].stringValue
    m.accountId = x["accountId"].stringValue
    m.courseId = x["courseId"].stringValue
    m.endTime = x["endTime"].stringValue
    m.startTime = x["startTime"].stringValue
    m.price = x["price"].stringValue
    m.type = x["type"].stringValue
    return m
}

func parseMyCourseList(all:[JSON])->[MyCourse]{
    var xList = [MyCourse]()
    for x in all {
        let f = parseMyCourse(x: x)
        xList += [f]
    }
    return xList
}

func parseTeacherCoursee(x:JSON)->TeacherCourse{
    var m = TeacherCourse()
    m.id = x["id"].stringValue
    m.status = x["status"].stringValue
    m.courseName = x["courseName"].stringValue
    m.classTime = x["classTime"].stringValue
    m.reServNum = x["reServNum"].stringValue
    m.isReServ = x["isReServ"].stringValue
    m.endTime = x["endTime"].stringValue
    m.startTime = x["startTime"].stringValue
    m.price = x["price"].stringValue
    m.type = x["type"].stringValue
    return m
}

func parseTeacherCourseList(all:[JSON])->[TeacherCourse]{
    var xList = [TeacherCourse]()
    for x in all {
        let f = parseTeacherCoursee(x: x)
        xList += [f]
    }
    return xList
}

func parseMyTeacher(x:JSON)->MyTeacher{
    var m = MyTeacher()
    m.teacherName = x["teacherName"].stringValue
    m.teacherMobile = x["teacherMobile"].stringValue
    m.teacherId = x["teacherId"].stringValue
    m.teacherImg = x["teacherImg"].stringValue
    m.placeName = x["placeName"].stringValue
    m.tcList = parseTeacherCourseList(all: x["courses"].arrayValue)
    return m
}

func parseReservations(x:JSON)->Reservations{
    var m = Reservations()
    m.accountId = x["accountId"].stringValue
    m.note = x["note"].stringValue
    m.courseName = x["courseName"].stringValue
    m.createTime = x["createTime"].stringValue
    m.price = x["price"].stringValue
    m.startTime = x["startTime"].stringValue
    m.endTime = x["endTime"].stringValue
    m.id = x["id"].stringValue
    m.courseId = x["type"].stringValue
    m.classTime = x["classTime"].stringValue
    m.status = x["status"].stringValue
    return m
}

func parseReservationsList(all:[JSON])->[Reservations]{
    var xList = [Reservations]()
    for x in all {
        let f = parseReservations(x: x)
        xList += [f]
    }
    return xList
}

func parseLearn(x:JSON)->Learn{
    var m = Learn()
    m.accountId = x["accountId"].stringValue
    m.type = x["type"].stringValue
    m.className = x["className"].stringValue
    m.createTime = x["createTime"].stringValue
    m.id = x["id"].stringValue
    return m
}

func parseLearnList(all:[JSON])->[Learn]{
    var xList = [Learn]()
    for x in all {
        let f = parseLearn(x: x)
        xList += [f]
    }
    return xList
}

func parseMyOrder(x:JSON)->MyOrder{
    var m = MyOrder()
    m.id = x["id"].stringValue
    m.orderType = x["orderType"].stringValue
    m.payStatus = x["payStatus"].stringValue
    m.payAmount = x["payAmount"].stringValue
    m.createTime = x["createTime"].stringValue
    m.payMethod = x["payMethod"].stringValue
    m.confirmdate = x["confirmdate"].stringValue
    m.confirmuser = x["confirmuser"].stringValue
    m.remark = x["remark"].stringValue
    m.outTradeNo = x["outTradeNo"].stringValue
    m.buyAccount = x["buyAccount"].stringValue
    m.courseId = x["courseId"].stringValue
    return m
}

func parseMyOrderList(all:[JSON])->[MyOrder]{
    var xList = [MyOrder]()
    for x in all {
        let f = parseMyOrder(x: x)
        xList += [f]
    }
    return xList
}

func parseTeacherOne(x:JSON)->TeacherOne{
    var m = TeacherOne()
    m.id = x["id"].stringValue
    m.name = x["name"].stringValue
    m.star = x["star"].stringValue
    m.picture = x["picture"].stringValue
    m.evaluates = x["evaluates"].stringValue
    m.level = x["level"].stringValue
    m.placeId = x["placeId"].stringValue
    m.placeName = x["placeName"].stringValue
    return m
}

func parseTeacherOneList(all:[JSON])->[TeacherOne]{
    var xList = [TeacherOne]()
    for x in all {
        let f = parseTeacherOne(x: x)
        xList += [f]
    }
    return xList
}

func parseQuestion(x:JSON)->Question{
    var m = Question()
    m.logId = x["logId"].stringValue
    m.testId = x["testId"].stringValue
    m.total = x["total"].stringValue
    m.question = x["question"]["question"].stringValue
    m.answer = x["question"]["answer"].stringValue
    m.id = x["question"]["id"].stringValue
    m.pic = x["question"]["pic"].stringValue
    m.classification = x["question"]["classification"].stringValue
    m.explains = x["question"]["explains"].stringValue
    m.type = x["question"]["type"].stringValue
    switch x["question"]["option1"].stringValue{
    case "":
        break
    default:
        m.options.append(x["question"]["option1"].stringValue)
    }
    
    switch x["question"]["option2"].stringValue{
    case "":
        break
    default:
        m.options.append(x["question"]["option2"].stringValue)
    }
    
    switch x["question"]["option3"].stringValue{
    case "":
        break
    default:
        m.options.append(x["question"]["option3"].stringValue)
    }
    
    switch x["question"]["option4"].stringValue{
    case "":
        break
    default:
        m.options.append(x["question"]["option4"].stringValue)
    }
    return m
}


func parseMyError(x:JSON)->MyError{
    var m = MyError()
    m.question = x["question"].stringValue
    m.createTime = x["createTime"].stringValue
    m.explains = x["explains"].stringValue
    return m
}

func parseMyErrorList(all:[JSON])->[MyError]{
    var xList = [MyError]()
    for x in all {
        let f = parseMyError(x: x)
        xList += [f]
    }
    return xList
}

func parseZXModel(x:JSON)->ZXModel{
    var m = ZXModel()
    m.id = x["id"].stringValue
    m.createTime = x["createTime"].stringValue
    m.total = x["total"].stringValue
    m.className = x["className"].stringValue
    m.classification = x["classification"].stringValue
    return m
}

func parseZXModelList(all:[JSON])->[ZXModel]{
    var xList = [ZXModel]()
    for x in all {
        let f = parseZXModel(x: x)
        xList += [f]
    }
    return xList
}

func parseTestRecord(x:JSON)->TestRecord{
    var m = TestRecord()
    m.id = x["id"].stringValue
    m.accountId = x["accountId"].stringValue
    m.finishTime = x["finishTime"].stringValue
    m.createTime = x["createTime"].stringValue
    m.count = x["count"].stringValue
    m.errorQuestions = x["errorQuestions"].stringValue
    return m
}

func parseTestRecordList(all:[JSON])->[TestRecord]{
    var xList = [TestRecord]()
    for x in all {
        let f = parseTestRecord(x: x)
        xList += [f]
    }
    return xList
}

func parseStringList(all:[JSON])->[String]{
    var xList = [String]()
    for x in all {
        let s = x.stringValue
        xList.append(s)
    }
    return xList
}

func parsePreOrder(x:JSON)->PreOrder{
    var m = PreOrder()
    m.totalPrice = x["totalPrice"].stringValue
    m.signupCount = x["signupCount"].stringValue
    m.discount = x["discount"].stringValue
    m.placeName = x["placeName"].stringValue
    m.installmentCount = x["installmentCount"].stringValue
    m.preCount = x["preCount"].stringValue
    m.defaultCount = x["defaultCount"].stringValue
    m.orderIds = parseStringList(all: x["orderIds"].arrayValue)
    m.signupNum = x["signupNum"].stringValue
    
    return m
}
